What is @ungap/url-search-params?
@ungap/url-search-params is a polyfill for the URLSearchParams interface, which allows you to work with the query string of a URL. It provides methods to easily create, manipulate, and parse URL query parameters.
What are @ungap/url-search-params's main functionalities?
Creating URLSearchParams
This feature allows you to create a new URLSearchParams object from a query string. The object can then be used to manipulate the query parameters.
const params = new URLSearchParams('key1=value1&key2=value2');
Appending Parameters
This feature allows you to append new parameters to the existing URLSearchParams object.
params.append('key3', 'value3');
Getting Parameter Values
This feature allows you to retrieve the value of a specific parameter from the URLSearchParams object.
const value = params.get('key1');
Deleting Parameters
This feature allows you to delete a specific parameter from the URLSearchParams object.
params.delete('key2');
Iterating Over Parameters
This feature allows you to iterate over all the parameters in the URLSearchParams object.
for (const [key, value] of params) { console.log(key, value); }
Other packages similar to @ungap/url-search-params
query-string
The query-string package provides utilities for parsing and stringifying URL query strings. It offers a more feature-rich API compared to @ungap/url-search-params, including support for nested objects and array values.
qs
The qs package is a query string parser with support for nested objects, arrays, and other advanced features. It is more powerful and flexible than @ungap/url-search-params, making it suitable for complex query string manipulations.
url-parse
The url-parse package is a lightweight URL parser that includes methods for working with query strings. It provides a more comprehensive solution for URL parsing and manipulation compared to @ungap/url-search-params.
URLSearchParams
The URLSearchParams polyfill.
Previously known as url-search-params.
All detections have been included and the code covered 100% (DOM patches are not measured on NodeJS though).
Live test
⚠ Webpack Users
If you have issues just requiring @ungap/url-search-params
, be sure you require @ungap/url-search-params/cjs
instead.
No issue should happen if you just import
the module instead.